home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / musicali / 8to16.lha / 8_to_16 / Sources / 8to16.asm next >
Assembly Source File  |  1992-09-02  |  7KB  |  476 lines

  1.  
  2. *    8to16 an interpolating converter 8-bit 2 16-bit samples
  3. *    version 1.0
  4. *    by IMMORTAL Systems
  5.  
  6. *    USAGE:    8to16 [-q] <filename>
  7.  
  8. *    Source text for PhxAss.U can do anything with it.
  9.  
  10. *    definitions:
  11.  
  12.     include exec.i
  13.     include dos.i
  14.     include PhxMacros.i
  15.  
  16.  
  17.  
  18. cIffHead = "FORM"
  19. c8svxHead = "8SVX"
  20. cVHDRHead = "VHDR"
  21. ctbufmax = 128
  22. cSizeOffset = 124
  23. cBodyID="BODY"
  24.  
  25. cRaw16Size = 8
  26. cIffHeadSize = $48
  27.  
  28.  
  29. * code section
  30.  
  31.         section PRG,code
  32.  
  33. * start is here :))))))))))))))))
  34.  
  35.  
  36.         move.l 4.w,a6
  37.         lea cDosName,a1
  38.         moveq #0,d0
  39.         jsr (OpenLibrary,a6)
  40.         tst.l d0
  41.         beq LNoDos
  42.         move.l d0,mDos
  43.         move.l d0,a6
  44.  
  45.  
  46. * load params...
  47.         lea mTbuf,a0
  48.         move.l a0,d1
  49.         move.l #ctbufmax,d2
  50.         moveq #0,d3
  51.         jsr (ReadItem,a6)
  52.         tst.l d0
  53.         beq LNothing
  54.         cmp.b #$2d,mTbuf  ;"-"
  55.         bne .somethingelse
  56.         jsr sParameters
  57.         lea mTbuf,a0
  58.         move.l a0,d1
  59.         move.l #ctbufmax,d2
  60.         moveq #0,d3
  61.         jsr (ReadItem,a6)
  62.         tst.l d0
  63.         beq LNothing
  64.  
  65. * filename is in mTubf NOW!
  66.  
  67. .somethingelse    
  68.  
  69. * advert
  70.         lea tMain,a0
  71.         jsr sPRINT
  72.  
  73.         lea mTbuf,a0
  74.         move.l a0,d1
  75.         move.l #1005,d2
  76.         jsr (Open,a6)
  77.         tst.l d0
  78.         bne .found
  79.         lea tNOTFOUND,a0
  80.         jsr sPRINT
  81.         jmp LErr1
  82. .found        move.l d0,mFH
  83.         move.l d0,d1
  84.         lea mEXBUF,a0
  85.         move.l a0,d2
  86.         jsr (ExamineFH,a6)
  87.         tst.l d0
  88.         beq LErr2
  89.         
  90. ;allocate memory
  91.  
  92.         lea mEXBUF,a0
  93.         add.l #cSizeOffset,a0
  94.         move.l (a0),d0
  95.         move.l d0,mSourceSize
  96.         moveq #0,d1
  97.         move.l 4.w,a6
  98.         jsr (AllocVec,a6)
  99.         tst.l d0
  100.         bne .memory
  101.         lea tNOMEM,a0
  102.         jsr sPRINT
  103.         jmp LErr2
  104.  
  105. ;load file
  106. .memory        move.l d0,mSource
  107.         move.l d0,d2
  108.         move.l mSourceSize,d3
  109.         move.l mFH,d1
  110.         move.l mDos,a6
  111.         jsr (Read,a6)
  112.  
  113. ;examine fileformat
  114.  
  115.         move.l mSource,a0
  116.         cmp.l #cIffHead,(a0)+
  117.         bne LRaw
  118.         add.l #4,a0
  119.         cmp.l #c8svxHead,(a0)+
  120.         bne LUnknownIFF
  121.         cmp.l #cVHDRHead,(a0)
  122.         bne LUnknownIFF
  123.  
  124. * IFF 8SVX FILE DETECTED..................
  125.  
  126.         move.l mSource,a0
  127.         move.l mSource,a1
  128.         add.l mSourceSize,a1
  129. .bodyscan    move.l (a0)+,d0
  130.         cmp.l #cBodyID,d0
  131.         beq .bodyfound
  132.         cmp.l a0,a1
  133.         bne .bodyscan
  134.         bra LUnknownIFF
  135. .bodyfound    move.l (a0)+,mSampleSize
  136.         move.l a0,mSample
  137.         lea tIFFOK,a0
  138.         jsr sPRINT
  139.         jmp LProcess
  140.  
  141. * RAW FILE DETECTED
  142.  
  143. LRaw        lea tRAWOK,a0
  144.         jsr sPRINT
  145.         move.l mSource,a0
  146.         move.l a0,mSample
  147.         move.l mSourceSize,d0
  148.         move.l d0,mSampleSize
  149.         jmp LProcess
  150.  
  151. * BAD IFF
  152.  
  153. LUnknownIFF    lea tBADIFF,a0
  154.         jsr sPRINT
  155.         jmp LErr3
  156.  
  157. * Process IT !!!!!!
  158.  
  159. LProcess    move.l mSampleSize,d0
  160.         bne .notempty
  161.  
  162. ; sample has length=0...leaving...
  163.  
  164.         lea tEMPTY,a0
  165.         jsr sPRINT
  166.         jmp LErr3
  167.  
  168. .notempty    move.l mSampleSize,d0
  169.                 asl.l #1,d0
  170.         move.l mDown,d7
  171.         bne .nodown
  172.         asl.l #1,d0
  173.         push.l a0
  174.         lea tDOWN,a0
  175.         jsr sPRINT
  176.         pop.l a0
  177. .nodown        add.l #cRaw16Size,d0
  178.         move.l d0,mDestSize
  179.         moveq #0,d1
  180.         move.l 4.w,a6
  181.         jsr (AllocVec,a6)
  182.         tst.l d0
  183.         bne .havemem
  184.         lea tNOMEM,a0
  185.         jsr sPRINT
  186.         jmp LErr3
  187. .havemem
  188.  
  189. * copy header
  190.         move.l d0,mDest
  191.         move.l d0,a0
  192.         move.l d0,a1
  193.         add.l mDestSize,a1
  194.         move.l a1,mDestOver
  195.         
  196.         move.l mRaw16Head,(a0)+
  197.         move.l mRaw16Head+4,(a0)+
  198.  
  199. * store
  200.  
  201.         move.l a0,mDestSample
  202.         move.l a0,a1
  203.  
  204. * completed: closing original file.....it will be DESTROYED!!!!
  205.         store
  206.         move.l mDos,a6
  207.         move.l mFH,d1
  208.         jsr (Close,a6)
  209.         recall
  210.  
  211. * init pointers for interpolation process
  212. *  a1=target.....DONE
  213. *  a0,source
  214.  
  215.         move.l mSample,a0
  216.  
  217. *  a2 = a0 limit
  218.         
  219.         move.l a0,a2
  220.         add.l mSampleSize,a2
  221.  
  222. * init done, starting process........
  223. ; d0=buffer a3=adr of last compared d1=count
  224. ; d2=last d5=interpolated words
  225.  
  226.         moveq #0,d5        
  227. .loop        moveq #0,d1
  228.         move.l a0,a3
  229.         move.b (a0)+,d2
  230.  
  231. .loop1        inc.l d1
  232.         move.l mDown,d7
  233.         bne .nodown2
  234.         inc.l d1
  235. .nodown2    cmp.l a2,a0
  236.         beq LDone
  237.         move.l a0,a3
  238.         move.b (a0)+,d7    
  239.         cmp.b d2,d7
  240.         beq .loop1
  241.  
  242.         
  243.         asl.w #8,d2
  244.         move.b (a3),d0
  245.         asl.w #8,d0
  246.         cmp.l #1,d1
  247.         bne .interpolateit
  248. ;write it
  249.         move.w d2,(a1)+
  250.         move.l a3,a0
  251.         jmp .loop
  252.  
  253. ;interpolation here
  254.  
  255. .interpolateit
  256.  
  257. ;compute step first
  258. ;= d3
  259.         move.w d0,d3
  260.         sub.w d2,d3
  261.         and.l #$0000FFFF,d3
  262.         ext.l d3
  263.         divs.w d1,d3
  264.         and.l #$FFFF,d3
  265.  
  266. ;d3.w = interpolation step
  267.  
  268. ;now write it to destination buffer !
  269. ;d4=write counter
  270.  
  271.         moveq #0,d4
  272.         move.w d2,d0
  273. .loop5        move.w d0,(a1)+
  274.         add.w d3,d0
  275.         inc.l d4
  276.         cmp.l d1,d4
  277.         bne .loop5
  278. ;done
  279.         add.l d1,d5
  280.         dec.l d5
  281.         move.l a3,a0
  282.         jmp .loop
  283.                 
  284. ;write rest of data        
  285. LDone        moveq #0,d4
  286.         asl.l #8,d2
  287. .loop6        move.w d2,(a1)+
  288.         inc.l d4
  289.         cmp.l d1,d4
  290.         bne .loop6
  291. ;done
  292.  
  293.  
  294.         lea tIDONE,a0
  295.         jsr sPRINT
  296.  
  297. ;write to file
  298.         lea mTbuf,a0
  299.         move.l a0,d1
  300.         move.l #1006,d2
  301.         move.l mDos,a6
  302.         jsr (Open,a6)
  303.         tst.l d0
  304.         bne .opened
  305.         lea tCANNOTOPEN,a0
  306.         jsr sPRINT
  307.         jmp LExit
  308. .opened        move.l mDest,d2
  309.         move.l mDestSize,d3
  310.         move.l d0,d1
  311.         move.l d0,mFH
  312.         jsr (Write,a6)
  313.         move.l mFH,d1
  314.         jsr (Close,a6)
  315.  
  316. ;file written
  317.  
  318.  
  319.         lea tEFFIC,a0
  320.         jsr sPRINT
  321.  
  322. ;compute efficiency --> d5
  323.  
  324.         and.l #$0000FFFF,d5
  325.         mulu.w #10,d5
  326.         move.l mSampleSize,d6
  327.         and.l #$0000FFFF,d6
  328.         divu.w d6,d5
  329.         and.l #$FFFF,d5
  330. ;print it
  331. .eflop        tst.l d5
  332.         beq .efdone
  333.         push.l d5
  334.         lea tE,a0
  335.         jsr sPRINT
  336.         pop.l d5
  337.         dec.l d5
  338.         jmp .eflop
  339.  
  340. .efdone        lea tE2,a0
  341.         jsr sPRINT
  342.         
  343.  
  344.  
  345.  
  346. * ALL DONE, EXITING
  347.  
  348. LExit        move.l 4.w,a6
  349.         move.l mSource,a1
  350.         jsr (FreeVec,a6)
  351.         move.l mDest,a1
  352.         jsr (FreeVec,a6)
  353.         move.l mDos,a1
  354.         jsr (CloseLibrary,a6)
  355.         moveq #0,d0
  356.         rts
  357.  
  358.  
  359. * -----------------------------------------------------------
  360.  
  361.  
  362.  
  363. LNothing
  364.  
  365. * advert
  366.         lea tMain,a0
  367.         jsr sPRINT
  368.  
  369.  
  370.         lea tUSAGE,a0
  371.         jsr sPRINT
  372.  
  373.     
  374. ;end
  375.  
  376.         move.l 4.w,a6
  377.         move.l mDos,a1
  378.         jsr (CloseLibrary,a6)
  379.         moveq #0,d0
  380.         rts
  381.  
  382. LNoDos        moveq #$2f,d0
  383.         rts
  384.         
  385.  
  386. LErr3        move.l 4.w,a6
  387.         move.l mSource,a1
  388.         jsr (FreeVec,a6)
  389. LErr2        move.l mDos,a6
  390.         move.l mFH,d1
  391.         jsr (Close,a6)
  392. LErr1        move.l 4.w,a6
  393.         move.l mDos,a1
  394.         jsr (CloseLibrary,a6)
  395.         moveq #20,d0
  396.         rts
  397.  
  398.  
  399. * SUBROUTINES ARE HERE
  400.  
  401. sEOL        lea mLF,a0
  402. sPRINT        store
  403.         cmp.l #0,mQuiet
  404.         beq .shutup
  405.         move.l a0,d1
  406.                               move.l mDos,a6
  407.         jsr (PutStr,a6)
  408. .shutup        recall
  409.         rts
  410.  
  411. sParameters    lea mTbuf,a0
  412. .loop        inc.l a0
  413.         tst.b (a0)
  414.         beq .endparam
  415.         move.b (a0),d0
  416.         cmp.b #'q',d0
  417.         bne .noq
  418.         move.l #0,mQuiet
  419. .noq        cmp.b #'d',d0
  420.         bne .loop
  421.         move.l #0,mDown
  422.         bra .loop
  423. .endparam    rts
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431. * data section
  432.  
  433.         section dt,data
  434. mId        dc.l 0
  435. mTbuf        dcb.b $80 ,0
  436. mQuiet        dc.l 1
  437. mDown        dc.l 1
  438. mLF        dc.b 10,0
  439. mDos        dc.l 0
  440. cDosName    dc.b "dos.library",0
  441. mFH        dc.l 0
  442. mSource        dc.l 0
  443. mSourceSize    dc.l 0
  444.  
  445. mSample        dc.l 0
  446. mSampleSize    dc.l 0
  447. mHex        dc.w 0
  448.  
  449. mEXBUF        dcb.l $40,0
  450.  
  451. mRaw16Head    dc.b "Raw16Bit"
  452. mDestSize    dc.l 0
  453. mDest        dc.l 0
  454. mDestSample    dc.l 0
  455. mDestOver    dc.l 0
  456.  
  457. tMain        dc.b 10,"8to16 v1.1 interpolating sample converter",10,"(c) 1997 IMMORTAL Systems",10,10,"IT'S FREEWARE. USE IT ON YOUR ^OWN^ RISK!",10,0
  458.  
  459.  
  460. tUSAGE        dc.b 10,"USAGE:  8to16 [-qd] <filename>",10,"-q QUIET -d OCTAVE DOWN",10,10,0
  461. tNOTFOUND    dc.b "File NOT found!",10,10,0
  462. tNOMEM        dc.b "Out of memory!",10,10,0
  463. tIFFOK        dc.b "Processing IFF-8SVX file...",10,10,0
  464. tRAWOK        dc.b "Processing 8-bit RAW file...",10,10,0
  465. tBADIFF        dc.b "Unsupported IFF file!",10,10,0
  466. tEMPTY        dc.b "Sample TOO short!",10,10,0
  467. tIDONE        dc.b "Interpolation done,saving buffer...",10,10,0
  468. tEFFIC        dc.b "Efficiency: [",0
  469. tE        dc.b "*",0
  470. tE2        dc.b "]",10,10,0
  471. tCANNOTOPEN    dc.b "Cannot open file for output!!!",10,10,0
  472. tDOWN        dc.b "Doubling sample rate to increase efficiency...",10,10,0
  473.  
  474.  
  475.  
  476.